<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>医院医疗废物管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/login.css" media="all">
</head>
<style type="text/css">
    html,
    body {
        width: 100%;
        height: 100%
    }
    
    body {
        background: url("__PUBLIC__/layuiadmin/layui/images/bg-login-body.jpg") no-repeat center center;
        background-size: cover;
    }
    
    .layui-form-item {
        margin-bottom: 25px;
    }
    
    .layui-form-select dl dd.layui-this {
        background-color: #1E9FFF;
        color: #fff;
    }
</style>

<body>
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
        <div class="layadmin-user-login-main" style="margin-top:8%">
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <select name="hid" id="select" lay-verify="required" class="layui-input">
                        <option value=""></option>
                    </select>
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="loginName" id="loginName" lay-verify="required" placeholder="用户名" class="layui-input">
                    <!-- <input type="text" name="hid" id="hid" placeholder="用户名" class="layui-input" style="display: none" value="223"> -->
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit lay-filter="LAY-user-login-submit" id="login">登 录</button>
                </div>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">

            <p style="color:white;font-size:18px">© 2018 运邦信息</p>
        </div>
    </div>

    <script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user'], function() {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin,
                form = layui.form,
                router = layui.router(),
                search = router.search;

            form.render();

            //提交
            form.on('submit(LAY-user-login-submit)', function(obj) {
                //请求登录接口
                admin.req({
                    url: "{:U( 'Home/index/login')}" //实际使用请改成服务端真实接口
                        ,
                    type: "post",
                    data: obj.field,
                    success: function(res) {
                        //请求成功后，写入 access_token
                        layui.data(setter.tableName, {
                            key: setter.request.tokenName,
                            value: res.data.access_token
                        });
                        if (res.code == 0) {
                            //登录成功的提示与跳转
                            layer.msg('登录成功', {
                                icon: 1,
                                time: 1000
                            }, function() {
                                location.href = "{:U( 'Home/index/index')}"; //后台主页
                            });
                        } else {
                            layer.msg('登录失败', {
                                icon: 2,
                                time: 1000
                            }, function() {
                                //location.href ="{:U( 'Home/index/index')}"; //后台主页
                            });
                        }
                    },

                });
            });
            $("#password").keydown(function(event) {
                event = event || window.event;
                if (event.keyCode == 13) {

                    //请求登录接口
                    admin.req({
                        url: "{:U( 'Home/index/login')}" //实际使用请改成服务端真实接口
                            ,
                        type: "post",
                        data: {
                            loginName: $('#loginName').val(),
                            password: $('#password').val(),
                            hid: $('#select option:selected').val()
                        },
                        success: function(res) {
                            //请求成功后，写入 access_token
                            layui.data(setter.tableName, {
                                key: setter.request.tokenName,
                                value: res.data.access_token
                            });
                            if (res.code == 0) {
                                //登录成功的提示与跳转
                                layer.msg('登录成功', {
                                    icon: 1,
                                    time: 1000
                                }, function() {
                                    location.href = "{:U( 'Home/index/index')}"; //后台主页
                                });
                            } else {
                                var s = '登录失败';
                                if ($('#loginName').val() == '') {
                                    s = s + ',用户名不能为空'
                                }
                                if ($('#password').val() == '') {
                                    s = s + ',密码不能为空'
                                }
                                layer.msg(s, {
                                    icon: 2,
                                    time: 2000
                                }, function() {
                                    //location.href ="{:U( 'Home/index/index')}"; //后台主页
                                });
                            }
                        },

                    });

                }
            })
            $("#loginName").keydown(function(event) {
                event = event || window.event;
                if (event.keyCode == 13) {

                    //请求登录接口
                    admin.req({
                        url: "{:U( 'Home/index/login')}" //实际使用请改成服务端真实接口
                            ,
                        type: "post",
                        data: {
                            loginName: $('#loginName').val(),
                            password: $('#password').val(),
                            hid: $('#select option:selected').val()
                        },
                        success: function(res) {
                            //请求成功后，写入 access_token
                            layui.data(setter.tableName, {
                                key: setter.request.tokenName,
                                value: res.data.access_token
                            });
                            if (res.code == 0) {
                                //登录成功的提示与跳转
                                layer.msg('登录成功', {
                                    icon: 1,
                                    time: 1000
                                }, function() {
                                    location.href = "{:U( 'Home/index/index')}"; //后台主页
                                });
                            } else {
                                var s = '登录失败';
                                if ($('#loginName').val() == '') {
                                    s = s + ',用户名不能为空'
                                }
                                if ($('#password').val() == '') {
                                    s = s + ',密码不能为空'
                                }
                                layer.msg(s, {
                                    icon: 2,
                                    time: 2000
                                }, function() {
                                    //location.href ="{:U( 'Home/index/index')}"; //后台主页
                                });
                            }
                        },

                    });

                }
            })
            $.ajax({
                url: "{:U('Home/Cust/region')}",
                type: "post",
                datatype: "json",
                success: function(res) {
                    $.each(res.data, function(index) {
                        var hid = res.data[index].value;
                        var name = res.data[index].n;
                        $("#select").append("<option value='" + hid + "'>" + name + "</option>")
                    })
                    form.render();
                }

            })

        });
    </script>
</body>

</html>